/**
 * Created by Administrator on 2016/7/6 0006.
 */
var time_swiper;
$(document).ready(function () {
    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = b_version.split(";");
    var trim_Version = version[1].replace(/[ ]/g, "");
    if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE6.0") {
        content_start();
        content_btn();
        carousel();
    }
    else if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE7.0") {
        content_start();
        content_btn();
        carousel();
    }
    else if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE8.0") {
        content_start();
        content_btn();
        carousel();
    } else {
    }
});
function content_start() {
    $(".swiper-slide").each(function (number) {
        $(".choice-btn").unbind();
        if (number == 0) {
            $(this).css("display", "block");
        }else {
            $(this).css("display", "none");
        }
    });
}

function content_btn() {
    $(".swiper-button-next").click(function () {
        $(".swiper-button-prev").css("display", "block");
        clearTimeout(time_swiper);
        $(".choice-btn").unbind();
        var num = "";
        var obj_next = "";
        $(".swiper-slide").each(function (index) {
            if ($(this).css("display") == "block") {
                if (index >= 4) {
                    return
                } else {
                    if (index == 3) {
                        $(".swiper-button-next").css("display", "none");
                    }
                    obj_next = $(this);
                    num = index;
                }
            }
        });
        if (num >= 0) {
            $(".swiper-slide").each(function (i) {
                if (i == num + 1) {
                    obj_next.css("display", "none");
                    $(this).css({"left": "0", "display": "block"});
                }
            })
        }
        content_btn();
        carousel();
    });
    $(".swiper-button-prev").click(function () {
        $(".swiper-button-next").css("display", "block");
        clearTimeout(time_swiper);
        $(".choice-btn").unbind();
        var num = "";
        var obj_next = "";
        $(".swiper-slide").each(function (index) {
            if ($(this).css("display") == "block") {
                if (index <= 0) {
                    return
                } else {
                    if (index == 1) {
                        $(".swiper-button-prev").css("display", "none");
                    }
                    obj_next = $(this);
                    num = index;
                }
            }
        });
        if (num >= 0) {
            $(".swiper-slide").each(function (i) {
                if (i == num - 1) {
                    obj_next.css("display", "none");
                    $(this).css({"left": "0", "display": "block"});
                }
            })
        }
        content_btn();
        carousel();
    })
}

function carousel() {
    time_swiper = setTimeout(function () {
        $(".choice-btn").unbind();
        var num;
        $(".swiper-slide").each(function (index) {
            if ($(this).css("display") == "block") {
                num = index + 1;
                if (num > 4) {
                    num = 0
                }
            }
        });
        carousel_ainimate(num);
    }, 5000);
}

function carousel_ainimate(num) {
    if (num > 0) {
        $(".swiper-button-prev").css("display", "block");
    }
    if (num < 4) {
        $(".swiper-button-next").css("display", "block");
    }
    if (num == 4) {
        $(".swiper-button-next").css("display", "none");
    }
    if (num == 0) {
        $(".swiper-button-prev").css("display", "none");
    }
    $(".swiper-slide").each(function (i) {
        if (i == num) {
            $(this).css({"display": "block", "left": "0"});
        } else {
            $(this).css("display", "none");
        }
    });
    content_btn();
    carousel();
}